import { validateIdNo, validatePhoneNegative, isMoney } from '@/utils/validate'

const trigger = ['blur']

const rules = ref({
  employeeName: [{ required: true, message: '请输入姓名', trigger }],
  jobTitle: [{ required: true, message: '请输入职称', trigger }],
  sex: [{ required: true, message: '请选择性别', trigger }],
  idno: [
    { required: true, message: '请输入身份证号', trigger },
    {
      validator: validateIdNo,
      message: '请正确的身份证号',
      trigger
    }
  ],
  political: [{ required: true, message: '请选择政治面貌', trigger }],
  workAge: [{ required: true, message: '请选择工龄', trigger }],
  position: [{ required: true, message: '请输入职务', trigger }],
  dealOrgName: [{ required: true, message: '请输入单位名称', trigger }],
  age: [
    { required: true, message: '请输入退休年龄', trigger },
    {
      validator: (rule, value, callback) => {
        const reg = /^[1-9]\d{0,}$/
        if (!reg.test(value)) {
          callback(new Error('请输入正确的年龄'))
        } else {
          callback()
        }
      },
      message: '请输入正确的年龄',
      trigger
    }
  ],

  applicationDate: [
    { required: true, message: '请输入退休办理日期', trigger },
    {
      validator: (rule, value, callback) => {
        const reg =
          /^(19|20|21)\d{2}-((0[1-9])|(1[012]))-(((0[1-9])|((1|2)[0-9]))|(3(0|1)))$/
        if (!reg.test(value)) {
          callback(new Error('请输入正确的日期 YYYY-MM-DD'))
        } else {
          callback()
        }
      },
      message: '请输入正确的日期 YYYY-MM-DD',
      trigger
    }
  ],
  normalRetirementTime: [
    { required: true, message: '请输入正常退休时间', trigger },
    {
      validator: (rule, value, callback) => {
        const reg =
          /^(19|20|21)\d{2}-((0[1-9])|(1[012]))-(((0[1-9])|((1|2)[0-9]))|(3(0|1)))$/
        if (!reg.test(value)) {
          callback(new Error('请输入正确的日期 YYYY-MM-DD'))
        } else {
          callback()
        }
      },
      message: '请输入正确的日期 YYYY-MM-DD',
      trigger
    }
  ],
  pension: [
    { required: true, message: '请输入养老金月标准', trigger },
    { validator: isMoney, message: '请输入正确的金额，至多两位小数', trigger }
  ],

  enterpriseAnnuity: [
    { required: true, message: '请输入年金', trigger },
    { validator: isMoney, message: '请输入正确的金额，至多两位小数', trigger }
  ],
  handedOverArea: [
    { required: true, message: '请输入档案移交街道/社区', trigger }
  ],
  handedOverTime: [
    { required: true, message: '请输入移交地方管理时间', trigger },
    {
      validator: (rule, value, callback) => {
        const reg =
          /^(19|20|21)\d{2}-((0[1-9])|(1[012]))-(((0[1-9])|((1|2)[0-9]))|(3(0|1)))$/
        if (!reg.test(value)) {
          callback(new Error('请输入正确的日期 YYYY-MM-DD'))
        } else {
          callback()
        }
      },
      message: '请输入正确的日期 YYYY-MM-DD',
      trigger
    }
  ],

  partyOrgIsBelong: [
    { required: true, message: '请输入党员组织关系是否转接属地管理', trigger }
  ],
  partyOrgStreetName: [
    { required: true, message: '请输入党员组织关系转接到的街道名称', trigger }
  ],
  currentAddress: [{ required: true, message: '请输入现居住地', trigger }],
  mobile: [
    { required: true, message: '请输入手机号', trigger },
    {
      validator: validatePhoneNegative,
      message: '请输入手机号',
      trigger
    }
  ]
})

export default rules
